package com.itheima.edu.info.manager.dao;

import com.itheima.edu.info.manager.domain.Student;
import com.itheima.edu.info.manager.domain.Teacher;

import java.util.ArrayList;

public class OtherTeacherDao implements BaseTeacherDao{
//    static Teacher[] teachers = new Teacher[5];
    ArrayList<Teacher> teachers = new ArrayList<>();

    public boolean addTeacher(Teacher teacher) {
        teachers.add(teacher);
        return true;
    }

    public Teacher[] findAllTeacher() {
        Teacher[] teacher1 = new Teacher[teachers.size()];
        for (int i = 0; i < teacher1.length; i++) {
            teacher1[i] = teachers.get(i);
        }
        return teacher1;
    }

    public void deleteTeacher(String tid) {
        for (int i = 0; i < teachers.size(); i++) {
            if (teachers.get(i) != null && tid.equals(teachers.get(i).getId())){
                teachers.remove(i);
            }
        }
    }

    public void updateTeacher(Teacher teacher) {
        for (int i = 0; i < teachers.size(); i++) {
            if (teachers.get(i) != null && teacher.getId().equals(teachers.get(i).getId())){
                teachers.set(i,teacher);
            }
        }
    }
}
